var prefix = jsctx + "/sys/msg";

var station = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 80;

    function load() {
        $('#exampleTable')

            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listMsg",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                     pageSize: 10,
                     pageList: [10, 20, 30],
                     pageNumber: 1,
                    sidePagination: "client",
                    paginationShowPageGo: true,
                    height: h,
                    // rightFixedColumns: true,
                    rightFixedNumber: 1,
                    // showColumns: false,
                    // cache: false,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,

                            stationType:$("#stationType").val(),
                            stationStaus:$("#stationStaus").val()

                        };
                    },


                    columns: [
                        {
                            field: 'roleId',
                            width: '100', align: 'center',
                            class: 'operate-td',
                            formatter: function (value, row, index) {
                                var ismsgType ="";
                                if(row.msgType==0){
                                    ismsgType="企业审核 ";
                                }else if(row.msgType==1){
                                    ismsgType="加盟商审核";

                                }else if(row.msgType==2){
                                    ismsgType="渠道商审核";

                                }else if(row.msgType==3){
                                    ismsgType="退款申请  ";
                                }else if(row.msgType==4){
                                    ismsgType="提现审核  ";
                                }else if(row.msgType==5){
                                    ismsgType="开票申请 ";
                                }else{
                                    ismsgType="其他";
                                }
                                var a = '<a onclick="station.readRcmsg('+row.msgNotificationId+',\''+row.msgUrl+'\')" class="ax_default box_2"  style="float: left;position: relative;">' ;

                                var b ='';
                                if(row.isRead==0){
                                    b ='<div style="background-color: red;width: 8px; height: 8px; border-radius: 10px;position: absolute;left:-17px;top: 17px; "></div>' ;
                                }
                                var c =   '   <div id="text" class="text ">' +
                                    '    <p style="font-size:16px;"><span style="color: #0C0C0C">'+ismsgType+'</span><span style="font-size:14px;">&nbsp; &nbsp; </span>' +
                                    '<span style="font-size:12px;color:#CCCCCC;">'+row.createdTime+'</span></p><p style="font-size:14px;">' +
                                    '<span style="color:#999999;">'+row.msgTitle+'</span></p>' +
                                '     </div>\n' +
                                '     </a>';

                                return a + b + c;
                            }
                        }
                    ]
                });
    }
    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function jumpDiscountPolicyPage(elecStationId) {
        location.href = prefix + "/jumpDiscountPolicyPage/" + elecStationId;
    };

//已读加跳转接口
    function readRcmsg(id,url) {
        // window.location.replace("/"+url);
        $.ajax({
            url: prefix + "/readMsg",
            type: "post",
            data: {
                'id': id
            },
            success: function (data) {
                if (data.status == 200) {
                    location.href = jsctx + url;
                } else {
                    layer.msg(data.message);
                }
            },
            error: function (xhr, error, exception) {
                let errorMsg = xhr.responseText;
                openMsg("error", "系统异常，" + errorMsg + "，请联系管理员！");
            }
        });

    }
    function clearMsg() {
        layer.confirm('确定要全部清理？', {
            btn: ['确定', '取消']
        }, function (index) {
            $.ajax({
                url: prefix + "/clear",
                type: "post",
                success: function (data) {
                    layer.close(index);
                    if (data.status == 200) {
                        layer.msg("删除成功");
                        $('#exampleTable').bootstrapTable('refresh'); //Table页面刷新
                    } else {
                        layer.msg(data.message);
                    }
                },
            });

        })
    }
    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        jumpDiscountPolicyPage: jumpDiscountPolicyPage,
        elecStationOut: elecStationOut,
        clearMsg: clearMsg,
        readRcmsg : readRcmsg

    };
})();

var addElecStation = (function () {
    function init() {

    };

    function getCheckedRoles() {
        var adIds = "";
        $("input:checkbox[name=role]:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
        });
        return adIds;
    }

    var isajaxsend = true;
    return {
        init: init
    };
})();


var elecStationOut = (function () {
    function init() {
    };

    function getCheckedRoles() {
        var adIds = "";
        $("input:checkbox[name=role]:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
        });
        return adIds;
    }

    var isajaxsend = true;

    function save() {
        if (isajaxsend) {
            var formData = new FormData($("#frmElecStationOut")[0]);
            $("#roleIds").val(getCheckedRoles());
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/saveOrUpdateElecStationOut",
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                beforeSend: function () {
                    isajaxsend = false
                },
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        parent.layer.msg("操作成功");
                        javascript:history.back(-1);
                    } else {
                        parent.layer.alert(data.message)
                    }

                },
                complete: function () {
                    isajaxsend = false
                }
            });
        }
    }




})();
